package net.zoneland.knowledge.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import net.zoneland.knowledge.model.GridDutyCommandosOrg;
import net.zoneland.knowledge.model.GridDutyCommandosUser;

/**
 * 网格，责任区，突击队信息查询接口.
 * @author bcc
 */
@Mapper
public interface GridDutyCommandosMapper {

    /**
     * 根据员工编号和数据类型查询人员关联的 网格，责任区，突击队信息.
     * @param ygId 员工编号
     * @param gdcType 数据类型
     * @return GRID网格,DUTY责任区，COMMANDOS突击队
     */
    @Select({
        "<script>",
        "select distinct PIID, TYPE_NAME, GDC_TYPE, YG_ID",
        "FROM AITK_GRID_DUTY_COMMANDOS_USER WHERE YG_ID  =  #{ygId} ",
        "<if test = \"gdcType != null \"> AND GDC_TYPE = #{gdcType} </if> ",
        "</script>"
    })
    @Results({
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "PIID", property = "piid", jdbcType = JdbcType.VARCHAR),
        @Result(column = "TYPE_NAME", property = "typeName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "GDC_TYPE", property = "gdcType", jdbcType = JdbcType.VARCHAR),
        @Result(column = "YG_ID", property = "ygId", jdbcType = JdbcType.VARCHAR)
    })
    List<GridDutyCommandosUser> getUserGdcInfoByYgIdAndGdcType(@Param("ygId") final String ygId,
                                                               @Param("gdcType") final String gdcType);
    /**
     * 根据党组织id和数据类型查询党组织关联的 网格，责任区，突击队信息.
     * @param orgUuid 党组织id
     * @param gdcType 数据类型
     * @return GRID网格,DUTY责任区，COMMANDOS突击队
     */
    @Select({
        "<script>",
        "select distinct PIID, TYPE_NAME, GDC_TYPE, ORG_UUID",
        "FROM AITK_GRID_DUTY_COMMANDOS_ORG WHERE ORG_UUID  =  #{orgUuid} ",
        "<if test = \"gdcType != null \"> AND GDC_TYPE = #{gdcType} </if> ",
        "</script>"
    })
    @Results({
        @Result(column = "ID", property = "id", jdbcType =  JdbcType.VARCHAR, id = true),
        @Result(column = "PIID", property = "piid", jdbcType = JdbcType.VARCHAR),
        @Result(column = "TYPE_NAME", property = "typeName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "GDC_TYPE", property = "gdcType", jdbcType = JdbcType.VARCHAR),
        @Result(column = "ORG_UUID", property = "orgUuid", jdbcType = JdbcType.VARCHAR)
    })
    List<GridDutyCommandosOrg> getOrgGdcInfoByOrgUuidAndGdcType(@Param("orgUuid") final String orgUuid,
                                                                @Param("gdcType") final String gdcType);


    @Select({
            "<script>",
            "select a.*,b.org_short_name from aitk_grid_duty_commandos_org a left join aitk_party_org b on a.org_uuid=b.org_uuid ",
            " <foreach collection=\"gridNames\" open=\"where TYPE_NAME in (\" separator=\",\" close=\")\" item=\"item\">#{item}</foreach>",
            "</script>"
    })
    @Results({
            @Result(column = "TYPE_NAME", property = "typeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ORG_SHORT_NAME", property = "orgShortName", jdbcType = JdbcType.VARCHAR)
    })
    List<GridDutyCommandosUser> getGridOrgShortNameByGridNames(@Param("gridNames") final List<String> gridNames);
}
